<c:if test="true" xmlns:f="http://java.sun.com/jsf/core"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:c="http://java.sun.com/jstl/core"
  xmlns:nxu="http://nuxeo.org/nxweb/util"
  xmlns:nxl="http://nuxeo.org/nxforms/layout"
  xmlns:nxp="http://nuxeo.org/nxweb/pdf"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:a4j="http://richfaces.org/a4j">

  <c:set var="namespace" value="#{widgetProperty_namespace}" />

  <c:if test="#{nxl:isLikePlainMode(widget.mode)}">
    <h:outputText
      value="#{select2Actions.resolveSingleReferenceLabel(field_0, widgetProperty_repository, widgetProperty_initOperationId, widgetProperty_idProperty,widgetProperty_labelProperty)}" />
  </c:if>

  <c:if test="#{widget.mode == 'pdf'}">
    <nxp:html>
    <h:outputText
      value="#{select2Actions.resolveSingleReferenceLabel(field_0, widgetProperty_repository, widgetProperty_initOperationId, widgetProperty_idProperty,widgetProperty_labelProperty)}" />
    </nxp:html>
  </c:if>

  <c:if
    test="#{nxl:isLikeViewMode(widget.mode) or widget.mode == 'edit'}">

    <nxu:set var="helpLabel"
      value="#{nxu:test(empty widgetProperty_helpLabel, messages['label.suggestion.help.minChars'], nxu:test(widget.translated, messages[widgetProperty_helpLabel], widgetProperty_helpLabel))}"
      cache="true">

      <ui:include src="/incl/select2_js.xhtml" />

      <a4j:region rendered="#{not empty field_0 || widget.mode == 'edit'}">
        <nxu:valueHolder id="#{widget.id}_select2" value="#{field_0}"
          required="#{widgetProperty_required}" var="currentValue">
          <h:inputHidden readonly="true" id="#{widget.id}_select2_init"
            value="#{select2Actions.resolveSingleReference(currentValue, widgetProperty_repository,widgetProperty_initOperationId, widgetProperty_idProperty,widgetProperty_documentSchemas)}" />
          <ui:insert name="inside_input_widget" />
        </nxu:valueHolder>

        <c:if test="#{not empty widgetProperty_ajaxReRender}">
          <a4j:jsFunction name="#{widget.id}_reRender"
            render="#{widgetProperty_ajaxReRender}" />
        </c:if>
      </a4j:region>

      <c:if
        test="#{widget.mode == 'edit' and !widgetProperty_hideHelpLabel}">
        <p class="detail">
          <h:outputFormat value="#{helpLabel}">
            <f:param value="#{widgetProperty_minChars}" />
          </h:outputFormat>
        </p>
      </c:if>

      <h:inputHidden readonly="true" id="#{widget.id}_select2_params"
        value="#{select2Actions.encodeParameters(widget, null, widgetProperties)}" />
      <h:message for="#{widget.id}_select2" styleClass="errorMessage" />

    </nxu:set>
  </c:if>

</c:if>